import { ref,reactive } from 'vue'
import { defineStore } from 'pinia'
import useTable from "@/hooks/useTable"
import useTableIncome from '@/hooks/useTableIncome'
import { 
  type TableDataInterface,
  type FormSearchInterface,
  type IncomeParamsInterface,
  type TableIncomeDataInterface 
} from '@/utils/interface'

export const useTableStore = defineStore('table', () => {
  // 表格加载数据状态
  const tableLoading = ref(true)
  // 表格数据最后更新时间
  const tableUpdateTime = ref('')
  // 表格数据类型
  const detailType = ref(1) // 1为支出 2为收入
  // 表格数据
  const tableList = ref<TableDataInterface[]>([]);
  // 收入表格数据
  const tableIncomeList = ref<TableIncomeDataInterface[]>([])
  // 搜索条件
  const form = ref<FormSearchInterface>({})
  // 页码
  const pagination = reactive({
    currentPage : 1,
    pageSize    : 20,
    background  : true,
    disabled    : false,
    total       : 0,
  })
  const formIncome      = ref<IncomeParamsInterface>({}) // 收入搜索数据
  const submitLoading   = ref(false) // 搜索按钮状态
  const downloadList    = ref([])    // 下载多条数据的列表
  const downloadBtnShow = ref(false) // 下载选中项按钮的显示隐藏
  return { form,formIncome,downloadList,downloadBtnShow,submitLoading,tableLoading,tableUpdateTime,detailType,tableList,tableIncomeList,pagination,...useTable(),...useTableIncome() }
})
